/**
 * Project:   warnme-app
 * File:      Event.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright: Bartosz Cichecki [ cichecki.bartosz@gmail.com ]
 * Date:      Mar 26, 2014
 */

package dtu.ds.warnme.app.model.impl;

import java.io.Serializable;

import android.location.Location;

import com.google.android.gms.maps.model.LatLng;

import dtu.ds.warnme.app.model.AbstractPOJO;
import dtu.ds.warnme.app.model.Mergeable;

/**
 * @author Bartosz Cichecki
 * 
 */
public class Event extends AbstractPOJO implements Serializable, Mergeable<Event> {

	private static final long serialVersionUID = 3319312715576707705L;

	protected Double latitude;

	protected Double longitude;

	protected EventType eventType;

	protected Integer reportsCount;

	protected Float bearing;

	protected String note;

	public Event() {
		super();
	}

	public Event(Double latitude, Double longitude, EventType eventType, Integer reportsCount, Float bearing, String note) {
		super();
		this.latitude = latitude;
		this.longitude = longitude;
		this.eventType = eventType;
		this.reportsCount = reportsCount;
		this.bearing = bearing;
		this.note = note;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!super.equals(obj)) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Event other = (Event) obj;
		if (bearing != other.bearing) {
			return false;
		}
		if (eventType != other.eventType) {
			return false;
		}
		if (latitude == null) {
			if (other.latitude != null) {
				return false;
			}
		} else if (!latitude.equals(other.latitude)) {
			return false;
		}
		if (longitude == null) {
			if (other.longitude != null) {
				return false;
			}
		} else if (!longitude.equals(other.longitude)) {
			return false;
		}
		if (note == null) {
			if (other.note != null) {
				return false;
			}
		} else if (!note.equals(other.note)) {
			return false;
		}
		if (reportsCount != other.reportsCount) {
			return false;
		}
		return true;
	}

	public Float getBearing() {
		return bearing;
	}

	public EventType getEventType() {
		return eventType;
	}

	public Double getLatitude() {
		return latitude;
	}

	public Location getLocation() {
		Location location = new Location("");
		location.setLatitude(latitude);
		location.setLongitude(longitude);
		location.setBearing(bearing);
		return location;
	}

	public Double getLongitude() {
		return longitude;
	}

	public String getNote() {
		return note;
	}

	public LatLng getPostition() {
		return new LatLng(latitude, longitude);
	}

	public int getReportsCount() {
		return reportsCount;
	}

	@Override
	public void merge(Event entity) {
		setEventType(entity.getEventType());
		setLatitude(entity.getLatitude());
		setLongitude(entity.getLongitude());
		setNote(entity.getNote());
		setReportsCount(entity.getReportsCount());
	}

	public void setBearing(Float bearing) {
		this.bearing = bearing;
	}

	public void setEventType(EventType eventType) {
		this.eventType = eventType;
	}

	public void setLatitude(Double lattitude) {
		latitude = lattitude;
	}

	public void setLocation(Location location) {
		latitude = location.getLatitude();
		longitude = location.getLongitude();
		bearing = location.getBearing();
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public void setPosition(LatLng latLng) {
		latitude = latLng.latitude;
		longitude = latLng.longitude;
	}

	public void setReportsCount(int reportsCount) {
		this.reportsCount = reportsCount;
	}

	@Override
	public String toString() {
		return "Event [latitude=" + latitude + ", longitude=" + longitude + ", eventType=" + eventType + ", reportsCount=" + reportsCount
		        + ", bearing=" + bearing + ", note=" + note + "]";
	}

}
